<?php
/**
 * 未知异常
 * User: Woozee
 * Date: 2021/1/15
 * Time: 22:51
 */

namespace App\Libs\Exceptions;

use App\Libs\Helpers\App;
use App\Libs\Helpers\Logger;
use App\Notifications\Notifiables\UncaughtExceptionOccurredNotifiable;

class UncaughtException extends BaseException
{
    public function __construct(\Throwable $e)
    {
        parent::__construct($e);

        //记录致命异常日志, 不能放在Report方法里, PHP语法解析错误不会进入Report方法中
        Logger::uncaught()->error(App::getExceptionContent($e));
        // 发送钉钉消息
        if (config('ding.enabled')) {
            $message = "未知异常提醒：\n{$e->getMessage()}";
            \Notification::send(new UncaughtExceptionOccurredNotifiable($message), new \App\Notifications\UncaughtExceptionOccurred());
        }
    }

    /**
     * 未知的错误, 不直接返回给用户
     * @return string
     */
    public function getUserMessage(): string
    {
        return '对不起，服务器内部错误！';
    }
}
